package com.demo.websocket;

import org.springframework.stereotype.Component;

import com.corundumstudio.socketio.SocketIOClient;
import com.outstading.plugin.netty.socketio.ConnectingHandler;
import com.outstading.plugin.netty.socketio.HandlerRegister;
import com.outstading.plugin.netty.socketio.SocketSender;
import com.outstanding.framework.base.TransactionLogger;
import com.outstanding.framework.core.Logger;
import com.outstanding.framework.core.PendingException;
import com.outstanding.framework.log.LoggerFactory;


@Component
public class ConnetStartHandler implements ConnectingHandler{
	
	
	protected Logger logger = LoggerFactory.getFrameworkLogger(HandlerRegister.class);

	
	@Override
	public void onConnect(SocketIOClient client) {
		int num  = client.get("count");
		TransactionLogger.debug("num="+num);
		if(num%2 ==1) {
			client.sendEvent("wating", "请等待其他玩家");
		}else {
			client.sendEvent("start", "开始游戏");
			try {
				SocketSender.sendMessageToUser(String.valueOf(num-1), "start", "开始游戏");
			} catch (PendingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
